package com.dlry.entity;
// Generated 2016-10-31 13:57:37 by Hibernate Tools 3.6.0.Final

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * DbLeave generated by hbm2java
 */
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
@Cacheable(true)
@Entity
@Table(name = "dl_leave")
public class DlLeave implements java.io.Serializable {

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	/**
	 * 
	 */
	@Transient
	private static final long serialVersionUID = 8604231809057154308L;
	@Transient
	private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd E");
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	@Column(name = "name")
	private String name;
	@Column(name = "from_time")
	private Timestamp fromTime;
	@Column(name = "to_time")
	private Timestamp toTime;
	@Column(name = "reason")
	private String reason;
	@Column(name = "type")
	private String type;
	@Column(name = "vail_code")
	private String vailCode;
	@Column(name = "created_date")
	private Timestamp createdDate;
	@ManyToOne(targetEntity = DlLoginuser.class)
	@JoinColumn(name = "userid")
	private DlLoginuser user;
	// bi-directional many-to-one association to DlWorkflow
	@OneToMany(mappedBy = "dlLeave", targetEntity=DlLeaveflow.class,fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	private List<DlLeaveflow> dlWorkflows;
	@Column(name = "flowing")
	private Boolean flowing;

	public DlLeave() {
	}

	public DlLeave(String name, Timestamp fromTime, Timestamp toTime) {
		this.name = name;
		this.fromTime = fromTime;
		this.toTime = toTime;
	}

	public DlLeave(String name, Timestamp fromTime, Timestamp toTime, String reason, String type, String vailCode) {
		this.name = name;
		this.fromTime = fromTime;
		this.toTime = toTime;
		this.reason = reason;
		this.type = type;
		this.vailCode = vailCode;
	}

	public void setUser(DlLoginuser user) {
		this.user = user;
	}

	public DlLoginuser getUser() {
		return user;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Timestamp getFromTime() {
		return this.fromTime;
	}

	public String getFromTimeStr() {
		return format.format(fromTime);
	}

	public void setFromTime(Timestamp fromTime) {
		this.fromTime = fromTime;
	}

	public void setFromTime(String fromTime) throws ParseException {
		Date date = format.parse(fromTime);
		Timestamp timestamp = new Timestamp(date.getTime());
		this.fromTime = timestamp;
	}

	public Timestamp getToTime() {
		return this.toTime;
	}

	public String getToTimeStr() {
		return format.format(toTime);
	}

	public void setToTime(String toTime) throws ParseException {
		Date date = format.parse(toTime);
		Timestamp timestamp = new Timestamp(date.getTime());
		this.toTime = timestamp;
	}

	public void setToTime(Timestamp toTime) {
		this.toTime = toTime;
	}

	public String getReason() {
		return this.reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getVailCode() {
		return this.vailCode;
	}

	public void setVailCode(String vailCode) {
		this.vailCode = vailCode;
	}

	public Timestamp getCreatedDate() {
		return createdDate;
	}

	public String getCreatedDateStr() {
		return format.format(createdDate);
	}

	public void setCreatedDate(Timestamp createdDate) {
		this.createdDate = createdDate;
	}

	public List<DlLeaveflow> getDlWorkflows() {
		return this.dlWorkflows;
	}

	public void setDlWorkflows(List<DlLeaveflow> dlWorkflows) {
		this.dlWorkflows = dlWorkflows;
	}

	public DlLeaveflow addDlWorkflow(DlLeaveflow dlWorkflow) {
		getDlWorkflows().add(dlWorkflow);
		dlWorkflow.setDlLeave(this);

		return dlWorkflow;
	}

	public DlLeaveflow removeDlWorkflow(DlLeaveflow dlWorkflow) {
		getDlWorkflows().remove(dlWorkflow);
		dlWorkflow.setDlLeave(null);

		return dlWorkflow;
	}

	public void setFlowing(Boolean flowing) {
		this.flowing = flowing;
	}

	public Boolean getFlowing() {
		return flowing;
	}

}
